using System.Collections.Generic;
using GameFrameworkLibraly.GlobalGameObjects;
using Microsoft.Xna.Framework;

namespace GameFrameworkLibraly.BaseObjects
{
    public abstract class GameHost
    {
        private GameObjectBase[] _objectArray;
        public List<GameObjectBase> GameObjects;

        public virtual void UpdateAll(GameTime gameTime)
        {
            int i;
            int objectCount=GameObjects.Count;

            if(_objectArray==null)
            {
                _objectArray = new GameObjectBase[(int) MathHelper.Max(20, GameObjects.Count*1.2f)];
            }
            else if(GameObjects.Count>_objectArray.Length)
            {
                _objectArray = new GameObjectBase[(int) (GameObjects.Count * 1.2f)];
            }

            for (i = 0; i < _objectArray.Length; i++)
            {
                if(i<GameObjects.Count)
                {
                    _objectArray[i] = GameObjects[i];
                }
                else
                {
                    _objectArray[i] = null;
                }
            }

            for (i = 0; i < objectCount; i++)
            {
                _objectArray[i].Update(gameTime);
            }
        }
    }
}
